package com.felix.ocoupon.converter;

import com.felix.ocoupon.constant.DistributeTarget;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author hsufelix
 * @email hsufelix@yeah.net
 * @Date 2020/11/12
 * DistributeTargetConverter
 * 枚举转换器
 */
@Converter
public class DistributeTargetConverter implements
        AttributeConverter<DistributeTarget, Integer> {

    @Override
    public Integer convertToDatabaseColumn(DistributeTarget target) {
        return target.getCode();
    }

    @Override
    public DistributeTarget convertToEntityAttribute(Integer code) {
        return DistributeTarget.of(code);
    }
}
